﻿using Shop.RemoteModel.AttrTemplate.Model;
using Shop.RemoteModel.GoodsSku.Model;
using Shop.StoreGatewayModular.Interface;
using WeDonekRpc.ApiGateway.Attr;
using WeDonekRpc.Helper.Validate;
using WeDonekRpc.HttpApiGateway;
using WeDonekRpc.HttpApiGateway.Model;

namespace Shop.StoreGatewayModular.Api
{
    [ApiRouteName("/shop/attr/template/{name}")]
    internal class AttrTemplateApi : ApiController
    {
        private readonly IAttrTemplateService _Service;

        public AttrTemplateApi (IAttrTemplateService service)
        {
            this._Service = service;
        }
        /// <summary>
        /// 添加属性摸版
        /// </summary>
        /// <param name="add"></param>
        /// <returns></returns>
        public long Add (AttrTemplateAdd add)
        {
            return this._Service.Add(add);
        }

        /// <summary>
        /// 删除属性摸版
        /// </summary>
        /// <param name="id"></param>
        public void Delete ([NullValidate("shop.attr.id.error")] long id)
        {
            this._Service.Delete(id);
        }
        public Dictionary<long, int> SetSort (LongParam<int> param)
        {
            return this._Service.SetSort(param.Id, param.Value);
        }
        /// <summary>
        /// 启用属性摸版
        /// </summary>
        /// <param name="id"></param>
        public void Enable ([NullValidate("shop.attr.id.error")] long id)
        {
            this._Service.Enable(id);
        }
        /// <summary>
        /// 获取属性摸版
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public AttrTemplate Get ([NullValidate("shop.attr.id.error")] long id)
        {
            return this._Service.Get(id);
        }
        /// <summary>
        /// 获取属性摸版树
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public AttrTemplateTree[] GetTrees (LongNullParam<bool?> param)
        {
            return this._Service.GetTrees(param.Id, param.Value);
        }
        /// <summary>
        /// 获取树形摸版
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public GoodsAttr[] GetAttrTrees ([NumValidate("shop.category.id.error", 1)] long categoryId)
        {
            return this._Service.GetAttrTrees(categoryId);
        }
        /// <summary>
        /// 修改属性摸版
        /// </summary>
        /// <param name="set"></param>
        /// <returns></returns>
        public bool Set (LongParam<AttrTemplateSet> set)
        {
            return this._Service.Set(set.Id, set.Value);
        }
        /// <summary>
        /// 停用属性摸版
        /// </summary>
        /// <param name="id"></param>
        public void Stop ([NullValidate("shop.attr.id.error")] long id)
        {
            this._Service.Stop(id);
        }
    }
}
